home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE02 / TPACK / TPACK.ZIP / USERNETW.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-06-01  |  9.2 KB  |  232 lines

  1. {------------------------------------------------------------------------------}
  2. {UNREGISTERED VERSION (6/1/95) PLEASE REDISTRIBUTE IN tPACK.ZIP!
  3.  This revision does not contain everything, nor are the exciting
  4.  DataSetReporter and ExtendedMenu[Item] components included.
  5.  Use SWREG#5906 to receive these, icons and a help file for $130.
  6.  You must register when using this code in a business application!
  7.  You'll receive a license to use this code in up to 50 copies of
  8.  any app you write. In turn you will get responsive e-mail
  9.  tech support and enhancements till I run out of registrations
  10.  or suggestions. Meanwhile.. enjoy the code. Bye! I'll make more.
  11.  {(C)'1995 Michael/Ax-Systems, 71560,1754@Compuserve.com}
  12. {------------------------------------------------------------------------------}
  13.  
  14. unit UserNetW;
  15.  
  16. {REQUIRES 'NOVELL' TO BE DEFINED FOR NOVEL FEATURES TO WORK. WILL BE FIXED.}
  17.  
  18. {-----------------------------------------------------------------------------------------}
  19. { USERNOV                                                                                 }
  20. {-----------------------------------------------------------------------------------------}
  21.  
  22. interface
  23.  
  24. uses
  25.   Classes,
  26.   PasUtils
  27.   ,UserInfo;
  28.  
  29. Const
  30.   NetWorkPasswordOk = 0;
  31.   NetWorkPasswordLockOut = 197;
  32.  
  33. Type
  34.   TNetWareUserInfo = class(TUserInfo)
  35.   {wraps some netware calls for easy access (gets the servername!) and can validate a
  36.   password against the users password}
  37.   private
  38.     fConnectID,
  39.     fConnectNumber : LongInt;                                { Default connection id }
  40.     pServerName  :PString;
  41.     pLoginName   :PString;
  42.     pFullName    :PString;
  43.     pLoginTime   :PString;
  44.   protected
  45.     function GetServerName:String;
  46.     function GetLoginName:String;
  47.     function GetFullName:String;
  48.     function GetLoginTime:String;
  49.     procedure SetNoString(const Value:String);
  50.   public
  51.     Constructor Create(aOwner:TComponent); Override;
  52.     Destructor Destroy; Override;
  53.     function UpdateOK:boolean; Override;
  54.     Function HasPassWord:Boolean;
  55.     Function CheckPassWord(const Value:String):Integer;
  56.   published
  57.     property ConnectID:Longint read fConnectID;
  58.     property ConnectNumber:Longint read fConnectNumber;
  59.  
  60.     property ServerName:String read GetServerName write SetNoString;
  61.     property LoginName:String read GetLoginName write SetNoString;
  62.     property FullName:String read GetFullName write SetNoString;
  63.     property LoginTime: String read GetLoginTime write SetNoString;
  64.     end;
  65.  
  66. {$IFDEF NOVELL}
  67. Function GetConnectionNumber : Integer;                    { Get novell connection number }
  68. Function GetConnectionInformation(ConId : LongInt;         { Get Novell connection info }
  69.            UserName : PChar; Var ObjType : Integer; Var ObjID : LongInt; LoginTime : PChar) : Integer;
  70. Function GetDefaultConnectionID : Integer;                 { Get Novell Default Connection ID }
  71. Function GetFileServerName(DefConID : LongInt;             { Get Novell File server Name }
  72.            FsName : PChar) : Integer;
  73. Function ReadPropertyValue(szUserName : PChar;             { Read a Novell property Value }
  74.            ObjType : Integer;szPropName : PChar;SegNum :  Integer;szLongName : PChar;
  75.            Var iMoreSegs : Char;Var iMoreFlags : Char) : Integer;
  76. Function VerifyBinderyObjectPassword(UserName : PChar;     { Verify a password against a bindery object }
  77.            BinType  : Integer; PassWord : PChar) : Integer;
  78. {$ENDIF}
  79.  
  80.  
  81. implementation
  82.  
  83. uses
  84.   Controls
  85.   ,SysUtils
  86.   ,Forms;
  87.  
  88. {-----------------------------------------------------------------------------------------}
  89. { NETWARE USER INFO                                                                       }
  90. {-----------------------------------------------------------------------------------------}
  91.  
  92. {$IFDEF NOVELL}
  93. Function GetConnectionNumber;         external 'NWNETAPI';
  94. Function GetConnectionInformation;    external 'NWNETAPI';
  95. Function GetDefaultConnectionID;      external 'NWNETAPI';
  96. Function GetFileServerName;           external 'NWNETAPI';
  97. Function ReadPropertyValue;           external 'NWNETAPI';    { Declare novell calls }
  98. Function VerifyBinderyObjectPassword; external 'NWNETAPI';
  99. {$ENDIF}
  100.  
  101. {-----------------------------------------------------------------------------------------}
  102. { OBJECT CREATION                                                                         }
  103. {-----------------------------------------------------------------------------------------}
  104.  
  105. Constructor TNetWareUserInfo.Create(aOwner:TComponent);
  106. begin
  107.   inherited Create(aOwner);
  108. {  Options:=[uifUpdateOnLoad,uifUpdateOnGet];}
  109.   pServerName:=NullStr;
  110.   pLoginName:=NullStr;
  111.   pFullName:=NullStr;
  112.   pLoginTime:=NullStr;
  113. end;
  114.  
  115. Destructor TNetWareUserInfo.Destroy;
  116. begin
  117.   DisposeStr(pLoginTime);
  118.   DisposeStr(pFullName);
  119.   DisposeStr(pLoginName);
  120.   DisposeStr(pServerName);
  121.   inherited Destroy;
  122. end;
  123.  
  124.  
  125. function TNetWareUserInfo.UpdateOK:boolean;
  126. var
  127.   fzServerName  : array [0..50] of Char;                   { File server Name }
  128.   fzLoginName   : array [0..50] of Char;                   { User Name }
  129.   fzFullName    : array [0..127] of Char;                  { Fill Name }
  130.   fzLoginTime   : array [0..9] of Char;                    { Login Time }
  131.   iRc : Integer;                                           { Return Type }
  132.   iOtype   : Integer;                                      { Object Type }
  133.   iOID : LongInt;                                          { Object Id }
  134.   iMoreSegs, iMoreFlags : Char;                            { Local Flags }
  135. begin
  136.   Result:=inherited UpdateOK;
  137.   if not Result then
  138.     Exit;
  139. {$IFDEF NOVELL}
  140.   fzServerName[0] := #0;                                   { Null FS name }
  141.   fzLoginName[0] := #0;                                    { Null User Name }
  142.   fzFullName[0] := #0;                                     { Fill Name }
  143.   fzLoginTime[0] := #0;                                    { Login Time }
  144.   fConnectID := GetDefaultConnectionID;                    { Get default connection ID }
  145.   fConnectNumber:= GetConnectionNumber;                    { Get connection Number }
  146.   iRc := GetConnectionInformation(                         { Get connection info }
  147.            fConnectNumber,@fzLoginName[0],iOtype,iOID,fzLoginTime);
  148.   if fzLoginName[0] = #0 then Exit;                        { If No User Name, No Net thus exit }
  149.   iRc := GetFileServerName(fConnectID,fzServerName);       { Get FS name }
  150.   iRc := ReadPropertyValue(                                { Get the user's full Name }
  151.            fzLoginName,iOtype,'IDENTIFICATION',1,fzFullName,iMoreSegs,iMoreFlags);
  152.   MovePChar2PString(pServerName,fzServerName,false);
  153.   MovePChar2PString(pLoginName,fzLoginName,false);
  154.   MovePChar2PString(pFullName,fzFullName,false);
  155.   MovePChar2PString(pLoginTime,fzLoginTime,false);
  156. {$ENDIF}
  157. end;
  158.  
  159. {-----------------------------------------------------------------------------------------}
  160. { OBJECT FUNCTIONS                                                                        }
  161. {-----------------------------------------------------------------------------------------}
  162.  
  163. Function TNetWareUserInfo.HasPassWord:Boolean;
  164. {since calling the VerifyBinderyObjectPassword function multiple times with the wrong pw
  165. can trigger the network's intruder alert and leave the user locked out when the log back in
  166. we're using two constants to get the value only once. Perhaps there is a system message that
  167. kicks in when a user changes names while logged in, but this will kick in just once per run.}
  168. const
  169.   init:Boolean=True; {could make a property}
  170.   HasPW:Boolean=False;
  171. begin
  172.   if Init then begin
  173.     Init:=False;
  174.     HasPW:=CheckPassWord('')<>NetWorkPasswordOk;
  175.     end;
  176.   Result:=HasPW; {true if the user has a network password}
  177. end;
  178.  
  179. Function TNetWareUserInfo.CheckPassWord(const Value:String):Integer;
  180. var
  181.   Cursor:TCursor;
  182.   zPWD: PChar;
  183.   zLoginName: PChar;
  184. begin
  185. {$IFDEF NOVELL}
  186.   Cursor:= Screen.Cursor;
  187.   Screen.Cursor := crHourGlass;                            { Start waiting }
  188.   zPWD:=MakePChar(Value);
  189.   zLoginName:=MakePChar(pLoginName^);
  190.   Result := VerifyBinderyObjectPassword(zLoginName,1,zPWD); { Verify against USER login name }
  191.   FreePChar(zLoginName);
  192.   FreePChar(zPWD);
  193.   Screen.Cursor := Cursor;
  194. {$ELSE}
  195.   Result:= NetWorkPasswordOk;
  196. {$ENDIF}
  197. end;
  198.  
  199. {-----------------------------------------------------------------------------------------}
  200. { PROPERTY PLUMBING                                                                       }
  201. {-----------------------------------------------------------------------------------------}
  202.  
  203. procedure TNetWareUserInfo.SetNoString(const Value:String);
  204. begin
  205. end;
  206.  
  207. function TNetWareUserInfo.GetServerName:String;
  208. begin
  209.   Result:=pServerName^;
  210. end;
  211.  
  212. function TNetWareUserInfo.GetLoginName:String;
  213. begin
  214.   Result:=pLoginName^;
  215. end;
  216.  
  217. function TNetWareUserInfo.GetFullName:String;
  218. begin
  219.   Result:=pFullName^;
  220. end;
  221.  
  222. function TNetWareUserInfo.GetLoginTime:String;
  223. begin
  224.   Result:=pLoginTime^;
  225. end;
  226.  
  227. {-----------------------------------------------------------------------------------------}
  228. {                                                                                         }
  229. {-----------------------------------------------------------------------------------------}
  230.  
  231. end.
  232.